package cn.wolfcode.web.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import cn.wolfcode.domain.Appointment;
import cn.wolfcode.domain.Business;
import cn.wolfcode.domain.SystemDictionary;
import cn.wolfcode.qo.AppointmentQueryObject;
import cn.wolfcode.service.IAppointmentService;
import cn.wolfcode.service.IBusinessService;
import cn.wolfcode.service.ISystemDictionaryItemService;
import cn.wolfcode.service.ISystemDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/user")
public class IndexController {

    @Autowired
private IBusinessService businessService;

    @Autowired
    private ISystemDictionaryItemService systemDictionaryItemService;

    @Autowired
    private IAppointmentService iAppointmentService;

    @Autowired
    private ISystemDictionaryService systemDictionaryService;
    @RequestMapping("/index")
    public String getIndex(Model model, AppointmentQueryObject qo){
     Business business = businessService.getStore();
        List<Business> businesses = businessService.listAll();
        model.addAttribute("businesses",businesses);
        model.addAttribute("business",business);
        List<SystemDictionary> systemDictionaries = systemDictionaryService.selectBusiness(qo);
        model.addAttribute("systemDictionaries",systemDictionaries);
        return "index";
    }

    @RequestMapping("message")
    public String getMessage(Appointment appointment){
        String yyyyMMddHHmmss = DateUtil.format(new Date(), "yyyyMMddHHmmss");
        String c = RandomUtil.randomNumbers(5);
        appointment.setAno(yyyyMMddHHmmss+c);
        appointment.setStatus(0);
        iAppointmentService.save(appointment);
        return "index";
    }
}
